//
//  InMainTabBarViewController.m
//  Inner  Voice
//
//  Created by brother on 16/3/1.
//  Copyright © 2016年 徐海宇. All rights reserved.
//

#import "InMainTabBarViewController.h"

#import "InNavController.h"

#import "RecommenViewController.h"

#import "InChannelViewController.h"

#import "AppDelegate.h"

#import "InManagementViewController.h"


@interface InMainTabBarViewController ()

@end

@implementation InMainTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addNavControllerTitle:@"推荐" imageName:@"tarbar _home2" selectImageName:@"tarbar _home1" className:@"RecommenViewController"];

    [self addNavControllerTitle:@"频道" imageName:@"tarbar _channel2" selectImageName:@"tarbar _channel1" className:@"InChannelViewController"];
    
//    [self addNavControllerTitle:@"朋友圈" imageName:@"tarbar _friend2" selectImageName:@"tarbar _friend1" className:@"FriendViewController"];
//    
    [self addNavControllerTitle:@"我的" imageName:@"tarbar _mine2" selectImageName:@"tarbar _mine1" className:@"InManagementViewController"];
    // Do any additional setup after loading the view.
}

- (void)resumed:(id)click {
    
   // [self.navigationController pushViewController:((AppDelegate *)[[UIApplication sharedApplication]delegate]).InPlayerViewController animated:YES];
    
   [self presentViewController:((AppDelegate *)[[UIApplication sharedApplication]delegate]).InPlayerViewController animated:YES completion:nil];
    
}

//- (void)search:(id)click {
//    NSLog(@"随机");
//}

- (void)addNavControllerTitle:(NSString *)title imageName:(NSString *)imageName selectImageName:(NSString *)selectImageName className:(NSString *)className {
    UIViewController *subClassContro = [[NSClassFromString(className) alloc] init];
//    UIBarButtonItem *Btn1 = [[UIBarButtonItem alloc] initWithTitle:@"随机" style:UIBarButtonItemStylePlain target:self action:@selector(search:)];
    
    UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"music_play"] style:UIBarButtonItemStylePlain target:self action:@selector(resumed:)];
    
//    subClassContro.navigationItem.leftBarButtonItem = Btn1;

    subClassContro.navigationItem.rightBarButtonItem = myButton;
    //    subClassContro.tabBarItem.title = title;
    subClassContro.navigationItem.title = title;
    // 设置tabBarItem系统的字体颜色 字体等属性
    NSDictionary *dic = @{NSForegroundColorAttributeName:[UIColor orangeColor]};
    [subClassContro.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected];
    
    subClassContro.tabBarItem.title = title;
    subClassContro.navigationItem.title = title;
    subClassContro.tabBarItem.image = [UIImage imageNamed:imageName];
    // 告诉系统 我的图片不需要渲染 采用原始的图片模式
    UIImage *selectImage = [[UIImage imageNamed:selectImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    subClassContro.tabBarItem.selectedImage = selectImage;
    
    InNavController *nav = [[InNavController alloc] initWithRootViewController:subClassContro];
    
    [self addChildViewController:nav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
